package com.wdj.comsumer.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.wdj.comsumer.msg.Result;
import com.wdj.comsumer.msg.ResultEnum;
import com.wdj.comsumer.msg.ResultUtil;
import com.wdj.dubboapi.entity.UserInfo;
import com.wdj.dubboapi.service.UserInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (UserInfo)表控制层
 *
 * @author makejava
 * @since 2020-07-06 11:52:21
 */
@RestController
@RequestMapping("userInfo")
public class UserInfoController {
    /**
     * 服务对象
     */
    @Reference
    private UserInfoService userInfoService;

    /**
     * 通过主键查询用户信息
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public UserInfo selectOne(Integer id) {
        return this.userInfoService.queryById(id);
    }

    @PostMapping("addOne")
    public Result addOne(@RequestBody String userName){
        boolean flag = userInfoService.insert(userName);
        if (flag){
            return ResultUtil.success(ResultEnum.SUCCESS.getMsg());
        }else{
            return ResultUtil.error(ResultEnum.UNKNOWN_ERROR.getCode(),ResultEnum.UNKNOWN_ERROR.getMsg());
        }

    }
}